import java.io.File;
import java.util.Iterator;
import java.util.List;

import javax.xml.stream.XMLStreamException;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.fyp.synchrona.blog.service.BloggerService;
import org.fyp.synchrona.core.info.impl.ICommonDataObject;
import org.fyp.synchrona.util.IDMMLData;
import org.fyp.synchrona.util.ITask;
import org.fyp.synchrona.util.IUpdate;

public class Main extends AttributeSets{
	
	static final Logger logger = Logger.getLogger(Main.class);
	
	public static void main(String arg[]){
		
		PropertyConfigurator.configure("/home/kapila/WS-WORKSPACE/SynchronizationTester/src/log4j.properties");
	
		File f = new File("/home/kapila/FYP/xml's/XML's/FB/contact info.xml");
		IDMMLData dmmlData = null;
		DMMLParser dmmlParser = DMMLParser.getDMMLParser();
		AttributeComparator comparator = AttributeComparator.getAttributeComparatorObject();
		ServiceManager sm = ServiceManager.getServiceMangerObject();
		
		/**
		 *Parse the XML and create account list and task list of update data. task list of update data 
		 *then passed to creating common profile object.   
		 */
		
		try {
		
			dmmlData = dmmlParser.parseXML(f);
			if(dmmlData==null){
				return;
			}
		
		} catch (XMLStreamException e) {
			
			e.printStackTrace();
			
		}
		
		Iterator i = dmmlData.getAccount().listIterator();
		Iterator i1 = dmmlData.getTask().listIterator();
		Account element = null;
		ITask element1 = null;
		System.out.println("\n");
		System.out.println("\n");
		System.out.println("###########################Testing DMML Data Object#############################");
		System.out.println("\n");
		
		/**
		 * printing service type
		 */
		
		
		System.out.println("+++++++++++++++++++++++++++Service Name ++++++++++++++++++++++++++++++++++++++++");
		System.out.println(dmmlData.getServiceName());
		System.out.println("+++++++++++++++++++++++++++Update Type++++++++++++++++++++++++++++++++++++++++++");
		System.out.println(dmmlData.getUpdateType());
		System.out.println("\n");
		System.out.println("\n");
		/**
		 * printing update data
		 */
		System.out.println("_+_+_+_+_+_+_+_+_+_+_+_+_+_update data+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_");
		while(i.hasNext()) {
			System.out.println("\n");
			element = (Account) i.next(); 
			System.out.println("+++++++++++++++++++++++++++service name+++++++++++++++++++++++++++++++++++++++++");
			System.out.print(element.getServiceName()+"\n");
			System.out.println("+++++++++++++++++++++++++++user name++++++++++++++++++++++++++++++++++++++++++++");
			System.out.print(element.getUserName()+"\n");
			System.out.println("+++++++++++++++++++++++++++password+++++++++++++++++++++++++++++++++++++++++++++");
			System.out.print(element.getUserName()+"\n");
			System.out.println("\n");
		} 
		
		while(i1.hasNext()) {
			System.out.println("\n");
			element1 = (Task) i1.next();
			System.out.println("+++++++++++++++++++++++++++tagname++++++++++++++++++++++++++++++++++++++++++++++");
			System.out.print(element1.getAttributeName()+"\n");
			System.out.println("+++++++++++++++++++++++++++tag value++++++++++++++++++++++++++++++++++++++++++++");
			System.out.print(element1.getAttributeValue()+"\n");
			System.out.println("\n");
		} 
		System.out.println("_+_+_+_+_+_+_+_+_+_+_+_+_+_update data_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+");
		System.out.println("\n");
		System.out.println("---------------------------DMMLData OBJECT TESTING FINISED----------------------");
		System.out.println("\n");
		System.out.println("###########################MODELING COMMON DATA OBJECT##########################");
		System.out.println("\n");
		System.out.println("\n");
		ICommonDataObject cdo = comparator.createCommonObject(dmmlData.getTask());
	    IUpdate updateObj = new Update();
	    System.out.println("\n");
	    System.out.println("\n");
	    System.out.println("---------------------------MODELING COMMONG DATA OBJECT FINISHED----------------");
	    System.out.println("\n");
	    System.out.println("\n");
	    updateObj.setServiceType(dmmlData.getServiceName());
	    updateObj.setCdo(cdo);
	    updateObj.setUpdateType(dmmlData.getUpdateType());
	    updateObj.setAccount(dmmlData.getAccount());
	   

	    System.out.println("***************************TESTING UPDATE OBJECT WHICH IS TO BE SENT THROUGH API");
	    System.out.println("\n");
	    System.out.println("\n");
		System.out.println("testing common profile object user name::"+updateObj.getCdo().getUSER_NAME());
		System.out.println("\n");
		System.out.println("testing common profile object birth day ::"+updateObj.getCdo().getBIRTH_DAY());
		System.out.println("\n");
		System.out.println("testing common profile object birht month ::"+updateObj.getCdo().getBIRTH_MONTH());
		System.out.println("\n");
		System.out.println("testing common profile object birth year ::"+updateObj.getCdo().getBIRTH_YEAR());
		System.out.println("\n");
		System.out.println("testing common profile object city ::"+updateObj.getCdo().getCITY());
		System.out.println("\n");
		System.out.println("testing common profile object country ::"+updateObj.getCdo().getCOUNTRY());
		System.out.println("\n");
		System.out.println("testing common profile object first name ::"+updateObj.getCdo().getFIRST_NAME());
		System.out.println("\n");
		System.out.println("testing common profile object last name ::"+updateObj.getCdo().getLAST_NAME());
		System.out.println("\n");
		System.out.println("testing common profile object full name ::"+updateObj.getCdo().getFULL_NAME());
		System.out.println("\n");
		System.out.println("testing common profile object username ::"+updateObj.getCdo().getUSER_NAME());
		System.out.println("\n");
		System.out.println("testing common profile object sex ::"+updateObj.getCdo().getSEX());
		System.out.println("\n");
		System.out.println("testing common profile object get state ::"+updateObj.getCdo().getSTATE());
		System.out.println("\n");
		System.out.println("testing common profile object username ::"+updateObj.getCdo().getUSER_NAME());
		System.out.println("\n");
		System.out.println("testing common profile object address ::"+updateObj.getCdo().getADDRESS());
		System.out.println("\n");
		System.out.println("testing common profile object bio ::"+updateObj.getCdo().getBIO());
		System.out.println("\n");
		System.out.println("testing common profile object courntry city ::"+updateObj.getCdo().getCOUNTRY_CITY());
		System.out.println("\n");
		System.out.println("testing common profile object current country city::"+updateObj.getCdo().getCURRENT_COUNTRY_CITY());
		System.out.println("\n");
		System.out.println("testing common profile object home phone::"+updateObj.getCdo().getHOME_PHONE());
		System.out.println("\n");
		System.out.println("testing common profile object mobile ::"+updateObj.getCdo().getMOBLIE());
		System.out.println("\n");
		System.out.println("testing common profile object photo height ::"+updateObj.getCdo().getPHOTO_HEIGHT());
		System.out.println("\n");
		System.out.println("testing common profile object photo url ::"+updateObj.getCdo().getPHOTO_URL());
		System.out.println("\n");
		System.out.println("testing common profile object photo width ::"+updateObj.getCdo().getPHOTO_WIDTH());
		System.out.println("\n");
		System.out.println("testing common profile object website ::"+updateObj.getCdo().getWEBSITE());
		System.out.println("\n");
		System.out.println("testing common profile object STATUS ::"+updateObj.getCdo().getSTATUS());
		System.out.println("\n");
		System.out.println("testing commong profile object EMAIL ::"+updateObj.getCdo().getEMAIL());
		System.out.println("\n");
		System.out.println("testing commong profile object INTERESTS ::"+updateObj.getCdo().getINTERESTS());

    	sm.updateServiceProfiles(updateObj);
	}

}
